//
//  ListSingerViewController.m
//  UI_xiangmu
//
//  Created by dllo on 15/4/24.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ListSingerViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+WebCache.h"
#import "ListSingerModel.h"
#import "ListSingerCell.h"
#import "onedeleCell.h"
#import "detailCamereViewController.h"
@interface ListSingerViewController ()

@property(nonatomic,retain)NSMutableArray *modelArr;

@end

@implementation ListSingerViewController


-(void)data1
{   NSLog(@"zhixingdata1");
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [NSString stringWithFormat:@"http://manhua.haomee.cn/?m=List&ios=23&pad=0&a=rankInfo&id=%@",self.canshu];
    NSLog(@"%@",str);
    [manager GET:str parameters:self success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.modelArr = [NSMutableArray array];
        NSMutableArray *arr = responseObject;
        for (NSMutableDictionary *dic in arr) {
            ListSingerModel *model = [[ListSingerModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.modelArr addObject:model];
            [model release];
        }
        [self.myCollectionView reloadData];
        [self.myTableView reloadData];
        NSLog(@"model %ld",self.modelArr.count);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"解析失败");
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    // Do any additional setup after loading the view.
    [self data1];
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    flowlayout.itemSize=CGSizeMake(100 , 150);
    
    //最小列间距
    flowlayout.minimumInteritemSpacing=10;
    //最小行间距
    flowlayout.minimumLineSpacing=5;
    flowlayout.scrollDirection=UICollectionViewScrollDirectionVertical;
    flowlayout.sectionInset=UIEdgeInsetsMake(10, 10, 15,15);
    self.myCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)  collectionViewLayout:flowlayout] ;
    self.myCollectionView.backgroundColor=[UIColor whiteColor];
    self.myCollectionView.dataSource=self;
    self.myCollectionView.delegate=self;
    [self.view addSubview:self.myCollectionView];
    //注册cell
    [self.myCollectionView registerClass:[ListSingerCell class] forCellWithReuseIdentifier:@"reuse1"];
    
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    
    [self.myCollectionView release];
    

}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.modelArr.count ;

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{       ListSingerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse1" forIndexPath:indexPath];
    NSString *str = [NSString stringWithFormat:@"%@_200_240.jpg",[self.modelArr[indexPath.row] cover]];
    NSURL *url = [NSURL URLWithString:str];
    [cell.myimage sd_setImageWithURL:url];
    cell.mylabel.text = [self.modelArr[indexPath.row] name];
    return cell;

}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    detailCamereViewController *de = [[detailCamereViewController alloc] init];
    de.canshu = [self.modelArr[indexPath.row] video_id];
    de.canshu = [NSString stringWithFormat:@"http://manhua.haomee.cn/?m=Api&ios=23&pad=0&a=getInfo&video_id=%@&uid=(null)",de.canshu];
    [self.navigationController pushViewController:de animated:YES];
    [de release];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
